/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controladores;

import entidades.ConvenioXPeriodoXEstudiante;
import entidades.ResumenSemPracProf;
import java.util.List;
import javax.ejb.EJBException;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author BATAQUERO
 */
@Stateless
public class ResumenSemPracProfFacade extends AbstractFacade<ResumenSemPracProf> implements ResumenSemPracProfFacadeLocal {
    @PersistenceContext(unitName = "KonbitacoraPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public ResumenSemPracProfFacade() {
        super(ResumenSemPracProf.class);
    }

    @Override
    public Integer obtenerMaxId() {
        Integer valorId;
        Query q = em.createNamedQuery("ResumenSemPracProf.findByMaxId");
        valorId = (Integer) q.getSingleResult();
        if (valorId != null) {
            valorId++;
        } else {
            valorId = 1;
        }
        return valorId;
    }

    @Override
    public ResumenSemPracProf consultarResumenSemestralPracticaProf(int idResumenSemestral) {
        try {
            Query q = em.createNamedQuery("ResumenSemPracProf.findByIdResumenSemPracProf");
            q.setParameter("idResumenSemPracProf", idResumenSemestral);
            ResumenSemPracProf resumenSemPracProf = (ResumenSemPracProf) q.getSingleResult();            
            em.refresh(resumenSemPracProf);
            em.flush();
            return resumenSemPracProf;
        } catch (EJBException eJBException) {
            return null;
        } catch (NoResultException noResultException) {
            return null;
        }
    }

    @Override
    public List<ResumenSemPracProf> consultarResumenSemestralPracticaProfEdicionFormato(ConvenioXPeriodoXEstudiante convenioXPeriodoXEstudiante, boolean edicionFormato) {
        try {
            Query q = em.createNamedQuery("ResumenSemPracProf.findByConvenioEdicionFormato");
            q.setParameter("convenioXPeriodoXEstudiante", convenioXPeriodoXEstudiante);
            q.setParameter("edicionFormato", edicionFormato);
            List<ResumenSemPracProf> resumenSemPracProf = (List<ResumenSemPracProf>) q.getResultList();            
            //em.refresh(calificacionDesempeno);
            em.flush();
            return resumenSemPracProf;
        } catch (EJBException eJBException) {
            return null;
        } catch (NoResultException noResultException) {
            return null;
        }
    }
    
}
